<?php

namespace App\Exceptions;


use Doctrine\Instantiator\Exception\InvalidArgumentException;
use Exception;

use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
use Illuminate\Http\Request;

use PHPUnit\Framework\MockObject\BadMethodCallException;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException;
use Throwable;
use luochuan\JWTAuth\Exceptions\JWTException;
use luochuan\JWTAuth\Exceptions\TokenExpiredException;
use luochuan\JWTAuth\Exceptions\TokenInvalidException;

class Handler extends ExceptionHandler
{
    /**
     * A list of the exception types that are not reported.
     *
     * @var string[]
     */
    protected $dontReport = [
        //
    ];

    /**
     * A list of the inputs that are never flashed for validation exceptions.
     *
     * @var string[]
     */
    protected $dontFlash = [
        'current_password',
        'password',
        'password_confirmation',
    ];

    /**
     * Register the exception handling callbacks for the application.
     *
     * @return void
     */
    public function register()
    {

        $this->reportable(function (Throwable $e) {
            //
        });
        $this->renderable(function (ApiException $e) {
            return response()->json([
                'code'=>$e->getCode(),
                'msg'=>$e->getMessage(),
                'data'=>''
            ]);
        });
        $this->renderable(function (TokenExpiredException $e) {
            return response()->json([
                'code'=>$e->getCode(),
                'msg'=>$e->getMessage(),
                'data'=>''
            ]);
        });
        $this->renderable(function (TokenInvalidException $e) {
            return response()->json([
                'code'=>$e->getCode(),
                'msg'=>$e->getMessage(),
                'data'=>''
            ]);
        });
        $this->renderable(function (MethodNotAllowedHttpException $e) {
            return response()->json([
                'code'=>$e->getCode(),
                'msg'=>$e->getMessage(),
                'data'=>''
            ]);
        });
        $this->renderable(function (JWTException $e) {
            return response()->json([
                'code'=>$e->getCode(),
                'msg'=>$e->getMessage(),
                'data'=>''
            ]);
        });
        $this->renderable(function (UnauthorizedHttpException $e) {
            return response()->json([
                'code'=>$e->getCode(),
                'msg'=>$e->getMessage(),
                'data'=>''
            ]);
        });

    }

}
